package com.shepin.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shepin.R;
import com.shepin.activity.ClothesFansizheBagActivity;
import com.shepin.bean.CategoryBean;
import com.shepin.horizontalmenu.HorizontalScrollMenu;

import java.util.List;

/**
 * Created by apple on 16/8/4.
 */
public class CategoryAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private HorizontalScrollMenu hsm_container;
    private List<CategoryBean>categoryBeanList;


    public  CategoryAdapter(Context context,List<CategoryBean>data){
        this.context=context;
        inflater=LayoutInflater.from(context);
        this.categoryBeanList=data;
    }
    @Override
    public int getCount() {
        return categoryBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return categoryBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view==null){
            view=inflater.inflate(R.layout.category_listview_item,null);
            holder=new ViewHolder();
            holder.name=(TextView)view.findViewById(R.id.category_clothes_name);
            holder.one=(TextView)view.findViewById(R.id.category_clothes_fansizhe);
            holder.two=(TextView)view.findViewById(R.id.category_clothes_anima);
            holder.three=(TextView)view.findViewById(R.id.category_clothes_luomeng);
            holder.four=(TextView)view.findViewById(R.id.category_clothes_four);
            holder.five=(TextView)view.findViewById(R.id.category_clothes_five);
            holder.six=(TextView)view.findViewById(R.id.category_clothes_jieni);
            holder.bitmap=(ImageView)view.findViewById(R.id.category_bitmap_iv);
            view.setTag(holder);
        }else{
            holder=(ViewHolder)view.getTag();
        }
        holder.name.setText(categoryBeanList.get(i).getCategoryName());
        holder.one.setText(categoryBeanList.get(i).getNames()[0]);
        holder.one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //复用activity  根据position去加载不同的数据进行显示
                switch (i){
                    case 0://服饰
                        Intent clothes=new Intent(context, ClothesFansizheBagActivity.class);
                        clothes.putExtra("clothes","fansizhe");
                        context.startActivity(clothes);
                        break;
                    case 1://箱包
                        Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                        bag.putExtra("bag","gucci");
                        context.startActivity(bag);
                        break;
                    case 2://酒品
                        Intent wine=new Intent(context, ClothesFansizheBagActivity.class);
                        wine.putExtra("wine","maikalun");
                        context.startActivity(wine);
                        break;
                    case 3://居家用品
                        Intent home=new Intent(context, ClothesFansizheBagActivity.class);
                        home.putExtra("home","zhuangshipin");
                        context.startActivity(home);
                        break;
                }
            }
        });
        holder.two.setText(categoryBeanList.get(i).getNames()[1]);
        holder.two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                context.startActivity(bag);
            }
        });
        holder.three.setText(categoryBeanList.get(i).getNames()[2]);
        holder.three.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                context.startActivity(bag);
            }
        });
        holder.four.setText(categoryBeanList.get(i).getNames()[3]);
        holder.four.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                context.startActivity(bag);
            }
        });
        holder.five.setText(categoryBeanList.get(i).getNames()[4]);
        holder.five.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                context.startActivity(bag);
            }
        });
        holder.six.setText(categoryBeanList.get(i).getNames()[5]);
        holder.six.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent bag=new Intent(context, ClothesFansizheBagActivity.class);
                context.startActivity(bag);
            }
        });
        holder.bitmap.setImageResource(categoryBeanList.get(i).getCategoryBitmap());
        return view;
    }
    public final class ViewHolder{
        public TextView name;
        public TextView one;
        public TextView two;
        public TextView three;
        public TextView four;
        public TextView five;
        public TextView six;
        public ImageView bitmap;
    }


}
